package com.sky.youxue.controller;

import com.sky.youxue.user.pojo.UserSize;
import com.sky.youxue.service.UserSizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping
public class UserSizeController {

    @Autowired
    private UserSizeService userSizeService;

    @PostMapping("insertUserSize")
    public ResponseEntity<Void> insertUserSize(@Valid UserSize userSize){
        Boolean result = userSizeService.insertUserSize(userSize);
        if(result == null || !result){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
        }
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PostMapping("updateUserSize")
    public ResponseEntity<Void> updateUserSize(@Valid UserSize userSize){
        System.out.println(userSize.getRolename()+","+userSize.getRoleid());
        Boolean result = userSizeService.updateUserSize(userSize);
        if(result == null || !result){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
        }
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @GetMapping("queryUserSize")
    public ResponseEntity<UserSize> queryUserSize(
            @RequestParam(value = "roleid",required = true) Long roleid
    ){
        UserSize userSize = userSizeService.queryUserSizeById(roleid);
        if (userSize==null){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
        }
        return ResponseEntity.status(HttpStatus.OK).body(userSize);
    }

    @GetMapping("deleteUserSize")
    public ResponseEntity<Void> deleteUserSize(@Valid UserSize userSize){
        Boolean result = userSizeService.deleteUserSize(userSize);
        if(result == null || !result){
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
        }
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
}
